//
//  WelfareRequestModel.swift
//  TianTianBiTing
//
//  Created by Gox mac 2 on 2019/2/25.
//  Copyright © 2019 Gox_WallyDiao. All rights reserved.
//

import UIKit
import Alamofire
import SwiftyJSON
import HandyJSON

class WelfareRequestModel: NSObject {
    class func loadWelfareListenData(completion:@escaping (_ succeed: Bool,_ message: String,_ bannerList: [WelfareListenModel]?) -> ()) {
        TTNetworkTools.getRequestData(URLString: TTURL_AllListenRank, jointArr: nil, parameters: ["startPoint":1,"maxPage":50]) { (json) in
            if json["code"].stringValue == SUCCESS {
                var bannerModels = [WelfareListenModel]()
                let dic = json["data"].dictionaryValue
                let arr = dic["data"]!.arrayValue
                for dic in arr {
                    let model = JSONDeserializer<WelfareListenModel>.deserializeFrom(dict: dic.dictionaryObject)
                    bannerModels.append(model!)
                }
                completion(true, json["message"].stringValue, bannerModels)
            } else {
                completion(false, json["message"].stringValue, nil)
            }
        }
    }
    
    class func loadWelfareIncomeData(para:String, completion:@escaping (_ succeed: Bool,_ message: String,_ bannerList: [WelfareIncomeModel]?) -> ()) {
        TTNetworkTools.getRequestData(URLString: TTURL_FindIncomeRanking, jointArr: nil, parameters: ["type":para]) { (json) in
            let jsonDic = json.arrayValue[0]
            if jsonDic["code"].intValue == 0 {
                var bannerModels = [WelfareIncomeModel]()
                let arr = jsonDic["list"].arrayValue
                for dic in arr {
                    let model = JSONDeserializer<WelfareIncomeModel>.deserializeFrom(dict: dic.dictionaryObject)
                    bannerModels.append(model!)
                }
                completion(true, json["msg"].stringValue, bannerModels)
            } else {
                completion(false, json["msg"].stringValue, nil)
            }
        }
    }
    
    class func loadWelfareItemData(completion:@escaping (_ succeed: Bool,_ message: String,_ bannerList: [WelfareItemModel]?) -> ()) {
        TTNetworkTools.getRequestData(URLString: TTURL_WelfareItem, jointArr: nil, parameters: ["platform":"1"]) { (json) in
            if json["code"].stringValue == "0" {
                var bannerModels = [WelfareItemModel]()
                let arr = json["data"].arrayValue
                for dic in arr {
                    let model = JSONDeserializer<WelfareItemModel>.deserializeFrom(dict: dic.dictionaryObject)
                    bannerModels.append(model!)
                }
                completion(true, json["message"].stringValue, bannerModels)
            } else {
                completion(false, json["message"].stringValue, nil)
            }
        }
    }
    
    class func loadSignInListData(parameters:[String : Any], completion:@escaping (_ succeed: Bool,_ message: String,_ bannerList: [SignInListModel]?) -> ()) {
        TTNetworkTools.getRequestData(URLString: TTURL_SignInList, jointArr: nil, parameters: parameters) { (json) in
            if json["code"].stringValue == SUCCESS {
                var bannerModels = [SignInListModel]()
                let arr = json["data"].arrayValue
                for dic in arr {
                    let model = JSONDeserializer<SignInListModel>.deserializeFrom(dict: dic.dictionaryObject)
                    bannerModels.append(model!)
                }
                completion(true, json["message"].stringValue, bannerModels)
            } else {
                completion(false, json["message"].stringValue, nil)
            }
        }
    }
    
    class func loadCurrentDaySignInData(completion:@escaping (_ succeed: Bool) -> ()) {
        TTNetworkTools.getRequestData(URLString: TTURL_CurrentDaySignIn
        , jointArr: nil, parameters: ["userId":String.getUserId()]) { (json) in
            if json["code"].stringValue == SUCCESS {
                let dic = json["data"].dictionaryValue
                if dic["currentDaySignIn"]?.intValue == 1 {
                   completion(true)
                } else {
                   completion(false)
                }
            } else {
                completion(false)
            }
        }
    }
    
    class func loadSignInRecordData(completion:@escaping (_ succeed: Bool) -> ()) {
        TTNetworkTools.getRequestData(URLString: TTURL_SignInRecord
        , jointArr: nil, parameters: ["userId":String.getUserId()]) { (json) in
            if json["code"].stringValue == SUCCESS {
                completion(true)
            } else {
                completion(false)
            }
        }
    }
    
    class func loadShareData(parameters:[String : Any], completion:@escaping (_ succeed: Bool,_ message: String,_ bannerList: [ShareModel]?) -> ()) {
        TTNetworkTools.getRequestData(URLString: TTURL_ProgramShare, jointArr: nil, parameters: parameters) { (json) in
            if json["code"].stringValue == SUCCESS {
                var bannerModels = [ShareModel]()
                let dic = json["data"].dictionaryValue
                let arr = dic["data"]!.arrayValue
                for dic in arr {
                    let model = JSONDeserializer<ShareModel>.deserializeFrom(dict: dic.dictionaryObject)
                    bannerModels.append(model!)
                }
                completion(true, json["message"].stringValue, bannerModels)
            } else {
                completion(false, json["message"].stringValue, nil)
            }
        }
    }
    
    class func loadMyShareData(jointArr:[Int], parameters:[String : Any], completion:@escaping (_ succeed: Bool,_ message: String,_ bannerList: [ShareModel]?) -> ()) {
        TTNetworkTools.getRequestData(URLString: TTURL_MyProgramShareGet, jointArr: jointArr, parameters: parameters) { (json) in
            if json["code"].stringValue == SUCCESS {
                var bannerModels = [ShareModel]()
                let dic = json["data"].dictionaryValue
                let arr = dic["data"]!.arrayValue
                for dic in arr {
                    let model = JSONDeserializer<ShareModel>.deserializeFrom(dict: dic.dictionaryObject)
                    bannerModels.append(model!)
                }
                completion(true, json["message"].stringValue, bannerModels)
            } else {
                completion(false, json["message"].stringValue, nil)
            }
        }
    }
    
    class func loadShareDetailsHeadData(jointArr:[Int], completion:@escaping (_ succeed: Bool,_ message: String,_ share: ShareModel?,_ share: [UserInfoModel]?) -> ()) {
        TTNetworkTools.getRequestData(URLString: TTURL_ShareProgramDetail, jointArr: jointArr, parameters: nil) { (json) in
            if json["code"].stringValue == SUCCESS {
                var shareModel = ShareModel()
                shareModel = JSONDeserializer<ShareModel>.deserializeFrom(dict: json["data"].dictionaryObject)!
                var userInfoModels = [UserInfoModel]()
                let dic = json["data"].dictionaryValue
                let arr = dic["shareUsers"]!.arrayValue
                for dic in arr {
                    let model = JSONDeserializer<UserInfoModel>.deserializeFrom(dict: dic.dictionaryObject)
                    userInfoModels.append(model!)
                }
                completion(true, json["message"].stringValue, shareModel, userInfoModels)
            } else {
                completion(false, json["message"].stringValue, nil, nil)
            }
        }
    }
    
    class func loadProgramShareData(parameters:[String : Any], completion:@escaping (_ succeed: Bool,_ message: String,_ bannerList: [ShareModel]?) -> ()) {
        TTNetworkTools.getRequestData(URLString: TTURL_ProgramShare, jointArr: nil, parameters: parameters) { (json) in
            if json["code"].stringValue == SUCCESS {
                var bannerModels = [ShareModel]()
                let dic = json["data"].dictionaryValue
                let arr = dic["data"]!.arrayValue
                for dic in arr {
                    let model = JSONDeserializer<ShareModel>.deserializeFrom(dict: dic.dictionaryObject)
                    bannerModels.append(model!)
                }
                completion(true, json["message"].stringValue, bannerModels)
            } else {
                completion(false, json["message"].stringValue, nil)
            }
        }
    }
}
